<template>
	<view class="content">
		<uni-nav-bar @clickLeft="toback" backgroundColor="#ffffff" left-icon="back" color="#15151B" :fixed="true"
			:statusBar="true" :border="false"></uni-nav-bar>
		<view class="title">
			<text>登录</text>
		</view>
		<view class="add-bagtop">
			<view class="bag-top">
				<view class="set-li">
					<view class="set-li-r">
						<view class="set-txt2">
							<input type="number" placeholder-style="color:#999999;font-size:34rpx" v-model="tel"
								placeholder="请输入您的用户名" />
						</view>
					</view>
				</view>
				<view class="set-li">
					<view class="set-li-r">
						<view class="set-txt2">
							<input type="password" placeholder-style="color:#999999;font-size:34rpx" v-model="pwd"
								placeholder="请输入密码" />
						</view>
					</view>
				</view>
			</view>
			<view class="btn1" @click="tologin()">
				<text>立即登录</text>
			</view>
			<view class="tip">
				<view @click="go('./register')">
					<text>立即注册 </text>
				</view>
				<view @click="go('./forgot')">
					<text>忘记账号或密码 </text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tel: '',
				pwd: '',
				url: '/pages/index/index',
			};
		},
		onLoad(option) {
			if(option.url){
				this.url = option.url;
			}
		},
		methods: {
			toback() {
				uni.switchTab({
					// url: "/pages/my/my",
					url: "/pages/index/index",
				})
			},
			tologin() {
				if (this.tel == "") {
					uni.showToast({
						icon: "none",
						title: "请输入账号",
					});
					return false;
				}
				if (this.pwd == "") {
					uni.showToast({
						icon: "none",
						title: "请输入密码",
					});
					return false;
				}
				this.$api.sendRequest({
					data:{
						service:'Login.userLogin',
						user_login:this.tel,
						user_pass:this.pwd,
						device:uni.getSystemInfoSync()['deviceId'],
					},
					success: res => {
						if(res.data.code == 0){
							var param = res.data.info[0];
							uni.setStorageSync('token',param['token']);
							uni.setStorageSync('uid',param['id']);
							uni.showToast({
								icon: "none",
								title: "登录成功",
							});
							setTimeout(() => {
								uni.switchTab({
									url: this.url,
								})
							}, 1000);
						}else{
							var msg = res.msg == '' ? res.data.msg : res.msg;
							uni.showToast({
								icon: "none",
								title: msg,
							});
							return false;
						}
						
					}
				});
				// uni.showLoading({
				// 	mask: true,
				// 	title: "请稍后",
				// });
				
				// uni.request({
				// 	url: this.$url + "/api/user/login",
				// 	method: "POST",
				// 	header: this.$header,
				// 	data: {
				// 		mobile: this.tel,
				// 		password: this.pwd,
				// 	},
				// 	success: (res) => {
				// 		uni.hideLoading();
				// 		console.log(res);
				// 		uni.showToast({
				// 			icon: "none",
				// 			title: res.data.msg,
				// 		});
				// 		if (res.data.code == 200) {
				// 			uni.setStorageSync("usertoken", res.data.data.userinfo.token);
				// 			uni.setStorageSync("userid", res.data.data.userinfo.id);
				// 			uni.setStorageSync("username", res.data.data.userinfo.username);
				// 			uni.setStorageSync("userinfo", res.data.data.userinfo);
				// 			setTimeout(() => {
				// 				uni.reLaunch({
				// 					url: '/pages/mine/mine'
				// 				})
				// 			}, 1000);
				// 		}
				// 	},
				// 	fail: () => {
				// 		uni.showToast({
				// 			icon: "none",
				// 			title: "登入失敗",
				// 		});
				// 	},
				// });
			},
			go(e) {
				uni.redirectTo({
					url: e
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #ffffff;

		.title {
			// margin-top: 50rpx;
			// margin-left: 40rpx;
			padding-top: 50rpx;
			padding-left: 40rpx;
			text {
				color: #3D3D3D;
				font-size: 48rpx;
			}
		}

		.add-bagtop {
			border-radius: 20rpx;
			padding-top: 40rpx;
			background-size: 100% 100%;
			background-repeat: no-repeat;
			width: 700rpx;
			margin: auto;
			margin-left: auto;
			position: relative;

			.bag-top {
				width: 660rpx;
				position: relative;
				margin: 40rpx auto;

				.set-li {
					display: flex;
					justify-content: space-between;
					padding: 25rpx 0;
					margin: 60rpx 0;
					align-items: center;
					border-bottom: 2rpx solid #e8e3e3;

					.set-li-r {
						flex: 1;

						.set-txt2 {
							input{
								font-size: 34rpx;
							}
							margin-right: 10rpx;
						}
					}
				}
			}

			.tip {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 24rpx;
				padding: 60rpx 20rpx;

				text {
					color: #666666;
				}
			}

			.btn1 {
				width: 660rpx;
				height: 90rpx;
				background-image: linear-gradient(270deg,
						rgba(96, 195, 254, 1) 0,
						rgba(197, 148, 254, 1) 100%);
				border-radius: 16rpx;
				text-align: center;
				line-height: 90rpx;
				margin: 0 auto;
				margin-top: 60rpx;

				text {
					font-size: 34rpx;
					color: #FFFFFF;
					letter-spacing: 6rpx;
				}
			}
		}
	}
</style>







</style>